import 'package:cmd_myapp_demo/components/My_App.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_animations/hero2_animation.dart';

void main() {
  runApp(const MyApp(child: _HeroAnimationPage()));
}

class _HeroAnimationPage extends StatefulWidget {
  const _HeroAnimationPage();

  @override
  _HeroAnimationState createState() => _HeroAnimationState();
}

class _HeroAnimationState extends State<_HeroAnimationPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Hero 动画1"),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: GestureDetector(
        child: const Hero(
          tag: 'hero1',
          child: CustomLogo(
            size: 200.0,
          ),
        ),
        onTap: () {
          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (BuildContext context) => const _Hero2AnimationPage(),
            ),
          );
        },
      ),
    );
  }
}

class _Hero2AnimationPage extends StatefulWidget {
  const _Hero2AnimationPage();

  @override
  _Hero2AnimationState createState() => _Hero2AnimationState();
}

class _Hero2AnimationState extends State<_Hero2AnimationPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Hero 动画2"),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: const Center(
        child: Hero(
          tag: 'hero1',
          child: CustomLogo(
            size: 300.0,
          ),
        ),
      ),
    );
  }
}

class CustomLogo extends StatelessWidget {
  final double size;

  const CustomLogo({super.key, this.size = 200.0});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.black26,
      width: size,
      height: size,
      child: const Center(
        child: FlutterLogo(
          size: 150.0,
        ),
      ),
    );
  }
}
